use tauri::{Manager, Wry};
use tauri_plugin_log::{Target, TargetKind};

pub fn setup_plugin(builder: tauri::Builder<Wry>) -> tauri::Builder<Wry> {
    builder
        .plugin(
            tauri_plugin_log::Builder::new()
                .targets([
                    Target::new(TargetKind::LogDir { file_name: None }),
                    Target::new(TargetKind::Stdout),
                ])
                .build(),
        )
        .plugin(tauri_plugin_shell::init())
        .plugin(tauri_plugin_dialog::init())
        .plugin(tauri_plugin_opener::init())
        .plugin(tauri_plugin_updater::Builder::new().build())
        .plugin(tauri_plugin_single_instance::init(|app, _, _| {
            let res = app
                .get_webview_window("main")
                .expect("no main window")
                .set_focus();
            if let Err(e) = res {
                log::warn!("failed to set focus: {}", e)
            }
        }))
}
